﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DTO;
using BUS;

namespace GUI
{
    public partial class FormTimKiemThongTinChung : Form
    {
        public FormTimKiemThongTinChung()
        {
            InitializeComponent();
        }

        private void FormTimKiemThongTinChung_Load(object sender, EventArgs e)
        {
            txtTimTheoTen.Enabled = false;
            txtTimTheoXeDangLai.Enabled = false;
            txtTimTheoMaNV.Enabled = false;
            //-----------------------------------------
            txtTimTheoMaKH.Enabled = false;
            txtTimTheoTenKhachHang.Enabled = false;
            txtTimTheoDiaDiem.Enabled = false;
        }

        private void cboxTimTheoTen_CheckedChanged(object sender, EventArgs e)
        {
            txtTimTheoTen.Enabled = true;
            txtTimTheoXeDangLai.Enabled = false;
            txtTimTheoMaNV.Enabled = false;
        }

        private void cboxTimTheoXeDangLai_CheckedChanged(object sender, EventArgs e)
        {
            txtTimTheoXeDangLai.Enabled = true;
            txtTimTheoTen.Enabled = false;
            txtTimTheoMaNV.Enabled = false;
        }

        private void cboxTimTheoMaNV_CheckedChanged(object sender, EventArgs e)
        {
            txtTimTheoMaNV.Enabled = true;
            txtTimTheoTen.Enabled = false;
            txtTimTheoXeDangLai.Enabled = false;
        }

        private void cboxTimTheoTenKhachHang_CheckedChanged(object sender, EventArgs e)
        {
            txtTimTheoTenKhachHang.Enabled = true;
            txtTimTheoMaKH.Enabled = false;
            txtTimTheoDiaDiem.Enabled = false;
        }

        private void cboxTimTheoDiaDiem_CheckedChanged(object sender, EventArgs e)
        {
            txtTimTheoDiaDiem.Enabled = true;
            txtTimTheoMaKH.Enabled = false;
            txtTimTheoTenKhachHang.Enabled = false;
        }

        private void cboxTimTheoMaKH_CheckedChanged(object sender, EventArgs e)
        {
            txtTimTheoMaKH.Enabled = true;
            txtTimTheoTenKhachHang.Enabled = false;
            txtTimTheoDiaDiem.Enabled = false;
        }

        private void btnTimThongTinTaiXe_Click(object sender, EventArgs e)
        {
            if (txtTimTheoTen.Enabled == true)
            {
                TaiXeDTO taixe = new TaiXeDTO();
                taixe.TenNhanVien = txtTimTheoTen.Text;
                if (TaiXeBUS.KiemTraTimThongTinXeTheoTen(taixe.TenNhanVien)==true)
                {
                    dataGridView1.DataSource = TaiXeBUS.TimThongTinTaiXeTheoTen(taixe.TenNhanVien);
                }
                else
                {
                    MessageBox.Show("Không Tìm Thấy Thông Tin", "Kiểm Tra Thông Tin");
                }
                return;
            }
            if (txtTimTheoXeDangLai.Enabled == true)
            {
                XeDTO xe = new XeDTO();
                xe.BienSo = txtTimTheoXeDangLai.Text;
                if (TaiXeBUS.KiemTraTimThongTinTaiXeTheoXeDangLai(xe.BienSo) == true)
                {
                    dataGridView1.DataSource = TaiXeBUS.TimThongTinTaiXeTheoXeDangLai(xe.BienSo);
                }
                else
                {
                    MessageBox.Show("Không Tìm Thấy Thông Tin", "Kiểm Tra Thông Tin");
                }              
                return;
            }
            if (txtTimTheoMaNV.Enabled == true)
            {
                TaiXeDTO taixe = new TaiXeDTO();
                taixe.MaTaiXe = txtTimTheoMaNV.Text;
                if (TaiXeBUS.KiemTraTimThongTinTaiXeTheoMaNhanVien(taixe.MaTaiXe) == true)
                {
                    dataGridView1.DataSource = TaiXeBUS.TimThongTinTaiXeTheoMaNhanVien(taixe.MaTaiXe);
                }
                else
                {
                    MessageBox.Show("Không Tìm Thấy Thông Tin", "Kiểm Tra Thông Tin");
                }                
                return;
            }
        }

        private void btnTimThongTinKhachHang_Click(object sender, EventArgs e)
        {
            if (txtTimTheoTenKhachHang.Enabled == true)
            {
                KhachHangDTO kh = new KhachHangDTO();
                kh.TenKhachHang = txtTimTheoTenKhachHang.Text;
                if (KhachHangBUS.KiemTraTimThongTinKhachHangTheoTen(kh.TenKhachHang) == true)
                {
                    dataGridView1.DataSource = KhachHangBUS.TimThongTinKhachHangTheoTen(kh.TenKhachHang);
                }
                else
                {
                    MessageBox.Show("Không Tìm Thấy Thông Tin", "Kiểm Tra Thông Tin");
                }
                return;
            }
            if (txtTimTheoDiaDiem.Enabled == true)
            {
                KhachHangDTO kh = new KhachHangDTO();
                kh.MaDiaDiem = txtTimTheoDiaDiem.Text;
                if (KhachHangBUS.KiemTraTimThongTinKhacHangTheoDiaDiem(kh.MaDiaDiem) == true)
                {
                    dataGridView1.DataSource = KhachHangBUS.TimThongTinKhacHangTheoDiaDiem(kh.MaDiaDiem);
                }
                else
                {
                    MessageBox.Show("Không Tìm Thấy Thông Tin", "Kiểm Tra Thông Tin");
                }
                return;
            }
            if (txtTimTheoMaKH.Enabled == true)
            {
                KhachHangDTO kh = new KhachHangDTO();
                kh.MaKH = txtTimTheoMaKH.Text;
                if (KhachHangBUS.KiemTraTimThongTinKhacHangTheoMaKhachHang(kh.MaKH) == true)
                {
                    dataGridView1.DataSource = KhachHangBUS.TimThongTinKhacHangTheoMaKhachHang(kh.MaKH);
                }
                else
                {
                    MessageBox.Show("Không Tìm Thấy Thông Tin", "Kiểm Tra Thông Tin");
                }
                return;
            }
        }
    }
}